package order;

import java.util.ArrayList;

public class OrderDAOArrayList  {
    private ArrayList<Order> orderArrayList = new ArrayList<>();


    public void addOrderData(Order O) {
        orderArrayList.add(O);
    }


    public Order findTheOrderByOrderNumber(String orderNumber) {
        long number = Long.parseLong(orderNumber);
        for (Order O:orderArrayList) {
            if(O.getOrderNumber() == number){
                return O;
            }
        }
        return null;
    }


    public ArrayList<Order> findTheUserNameByOrderNumber(String userName) {
        ArrayList<Order> orders = new ArrayList<>();
        for (Order O:orderArrayList) {
            if(O.getUserName().equals(userName)){
                orders.add(O);
            }
        }
        return orders;
    }

    public ArrayList<Order> getOrderArrayList() {
        return orderArrayList;
    }

    public ArrayList<String> getOrderStringArrayList(){
        ArrayList<String> strings = new ArrayList<>();
        for (Order O:orderArrayList) {
            StringBuilder str = new StringBuilder();
            str.append(O.getOrderNumber()).append(" ").append(O.getTime()).append(" ").append(O.getGoods().getName()).append(" ").append(O.getGoods().getPrice()).append(" ").append(O.getGoods().getAmount());
            strings.add(new String(str));
        }
        return strings;
    }
}
